<template>
    <div>
        <h1>会员等级添加</h1>
        <table class="table">
            <thead>
                <tr>
                    <td>等级名称</td>
                    <td><input type="text" v-model="data.LeveName"></td>
                </tr>
                <tr>
                    <td>会员状态</td>
                    <td>
                        <input type="radio" name="LeveState" :value="'true'" v-model="data.LeveState">启用
                        <input type="radio" name="LeveState" :value="'false'" v-model="data.LeveState">禁用
                    </td>
                </tr>
                <tr>
                    <td>会员等级</td>
                    <td>
                        <select v-model="data.QYId">
                            <option value="0">请选择</option>
                            <option v-for="a in bang" :value="a.QYId">{{a.QYName}}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="新增" @click="Add"></td>
                </tr>
            </thead>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref ,onMounted} from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';

const router = useRouter()
onMounted(()=>{
    Xia()
})

//下拉框
const bang =ref([{
    "QYId": 0,
    "QYName": "",
    "QYState": true,
    "QYIsDelete": true
}])

const Xia = ()=>{
    axios.get('https://localhost:7174/api/Leve/Xia').then(res=>{
        bang.value = res.data;
    })
}


//新增
const data = ref({
    "LeveId": 0,
  "LeveName": "",
  "LeveState": true,
  "QYId": 0
})

const Add=()=>{
    if(data.value.LeveName==""){
        alert('等级名称不能为空')
        return
    }
    if(data.value.LeveName=="全国会员"){
        alert('等级名称不能重复')
        return
    }
    if(data.value.LeveName=="普通会员"){
        alert('等级名称不能重复')
        return
    }
    axios.post('https://localhost:7174/api/Leve/LeveAdd',data.value).then(res=>{
        if(res.data>0){
            alert('新增成功');
            router.push({path:"/LeveShow"})
        }
        else{
            alert('新增失败')
        }
    })
}







</script>

<style scoped>

</style>